home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic 4 Database How-To
/
Visual Basic 4 Database - How-to (The Waite Group)(1995).iso
/
attach.fr_
/
attach.fr
Wrap
Text File
|
1995-02-12
|
7KB
|
226 lines
VERSION 4.00
Begin VB.Form frmAttach
BackColor = &H00C0C0C0&
Caption = "Attachment Manager"
ClientHeight = 2910
ClientLeft = 1095
ClientTop = 1515
ClientWidth = 4200
BeginProperty Font
name = "MS Sans Serif"
charset = 1
weight = 700
size = 8.25
underline = 0 'False
italic = 0 'False
strikethrough = 0 'False
EndProperty
Height = 3315
Left = 1035
LinkTopic = "Form1"
ScaleHeight = 2910
ScaleWidth = 4200
Top = 1170
Width = 4320
Begin VB.CommandButton cmdClose
Caption = "&Close"
Height = 555
Left = 1200
TabIndex = 2
Top = 1860
Width = 1815
End
Begin VB.CommandButton cmdDetach
Caption = "&Detach a Table"
Height = 555
Left = 1200
TabIndex = 1
Top = 1080
Width = 1815
End
Begin VB.CommandButton cmdAttach
Caption = "&Attach a Table"
Height = 555
Left = 1200
TabIndex = 0
Top = 300
Width = 1815
End
Begin MSComDlg.CommonDialog cmDlgFile
Left = 180
Top = 1920
_version = 65536
_extentx = 847
_extenty = 847
_stockprops = 0
End
End
Attribute VB_Name = "frmAttach"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
Option Explicit
Const SOURCE_FILE = 1
Const DESTINATION_FILE = 2
Const DETACH_FILE = 3
Private Sub cmdAttach_Click()
' Get the user's choice of the file to which the table
' is to be attached
GetMDBFile DESTINATION_FILE
' If the user chose a destination file, get the source of the
' table from the user
If DestinationFile.Name <> "" Then GetMDBFile SOURCE_FILE
If SourceFile.Name <> "" Then
' The user designated a destination file and a source file.
' Use frmSelector to get the user's selection of the source
' file table to be attached to the destination file.
frmSelector.Tag = "Attach"
frmSelector.Show 1
' The user designated a table, so attach it.
If TableName <> "" Then AttachTable
End If
End Sub
Private Sub cmdDetach_Click()
' Get the user's choice of the file from which the table
' is to be detached
GetMDBFile DETACH_FILE
If DestinationFile.Name <> "" Then
' The user designated a file.
' Use frmSelector to get the user's selection of the source
' file table to be detached from the file.
frmSelector.Tag = "Detach"
frmSelector.Show 1
' The user designated a table, so detach it.
If TableName <> "" Then DetachTable
End If
End Sub
Private Sub cmdClose_Click()
End
End Sub
Private Function ExtractPath(fileName As String, fullPath As String)
' Extract the pathname from the fully quialified filename and
' return the pathname to the calling routine.
ExtractPath = Left$(fullPath, Len(fullPath) - (Len(fileName) + 1))
End Function
Private Sub DetachTable()
Dim db As Database
' Set the error handler.
On Error GoTo DetachTableError
' Open the database specified in the Public variable DestinationFile.
Set db = DBEngine.Workspaces(0).OpenDatabase(DestinationFile.Path _
& "\" & DestinationFile.Name)
' Delete the table definition designated by the Public variable
' TableName.
db.TableDefs.Delete TableName
MsgBox "Table " & TableName & " detached from " & DestinationFile.Name
Exit Sub
DetachTableError:
MsgBox Error(Err)
Exit Sub
End Sub
Private Sub AttachTable()
Dim db As Database
Dim tblDef As TableDef
Dim dotPos As Integer
' Set the error handler.
On Error GoTo AttachFileError
' Open the database specified in the Public variable DestinationFile.
Set db = DBEngine.Workspaces(0).OpenDatabase(DestinationFile.Path _
& "\" & DestinationFile.Name)
' Create the table definition and set its properties. The table name
' is contained in the Public variable SourceFile.
Set tblDef = db.CreateTableDef(TableName)
tblDef.Connect = ";DATABASE=" & SourceFile.Path & "\" & SourceFile.Name
tblDef.SourceTableName = TableName
' Add the table definition to the destination file's TableDefs
' collection.
db.TableDefs.Append tblDef
MsgBox "Table " & TableName & " attached to " & DestinationFile.Name
Exit Sub
AttachFileError:
MsgBox Error(Err)
Exit Sub
End Sub
Private Sub GetMDBFile(purpose As Integer)
' Set the error handler.
On Error GoTo GetMDBFileError
' Set the caption property for the File Open common dialog.
Select Case purpose
Case SOURCE_FILE
cmDlgFile.DialogTitle = "Select Source File Of Table"
Case DESTINATION_FILE
cmDlgFile.DialogTitle = "Select File To Attach Table To"
Case DETACH_FILE
cmDlgFile.DialogTitle = "Select File To Detach Table From"
End Select
' Set the remaining properties for the File Open common dialog.
' The dialog will facilitate selection of an existing MS Access file.
cmDlgFile.DefaultExt = "*.MDB"
cmDlgFile.Filter = "Access Files *.MDB|*.MDB|All Files *.*|*.*"
cmDlgFile.Flags = &H1000 ' OFN_FILEMUSTEXIST
cmDlgFile.CancelError = True
cmDlgFile.fileName = "*.MDB"
' Open the dialog box and get the user's selection.
cmDlgFile.ShowOpen
' From the user's selection, update the Name and Path members of
' the appropriate Public variable.
If purpose = SOURCE_FILE Then
SourceFile.Name = cmDlgFile.FileTitle
SourceFile.Path = ExtractPath(cmDlgFile.FileTitle, _
cmDlgFile.fileName)
Else
DestinationFile.Name = cmDlgFile.FileTitle
DestinationFile.Path = ExtractPath(cmDlgFile.FileTitle, _
cmDlgFile.fileName)
End If
Exit Sub
GetMDBFileError:
' The user clicked Cancel in the File Open dialog box. Set the members
' of the appropriate Public variable to empty strings.
If purpose = SOURCE_FILE Then
SourceFile.Name = ""
SourceFile.Path = ""
Else
DestinationFile.Name = ""
DestinationFile.Path = ""
End If
Exit Sub
End Sub